package com.kezesong.leasing.service.impl;

import com.kezesong.leasing.entity.GoodsColorEntity;
import com.kezesong.leasing.mapper.GoodsColorMapper;
import com.kezesong.leasing.service.GoodsColorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Date;
import java.util.List;

@Service
public class GoodsColorServiceImpl implements GoodsColorService {

    @Autowired
    private GoodsColorMapper goodsColorMapper;

    @Override
    public List<GoodsColorEntity> getGoodsColorList() {
        return goodsColorMapper.selectAll();
    }

    @Override
    public List<GoodsColorEntity> getGoodsColorList(int goodsId) {
        Example example = new Example(GoodsColorEntity.class);
        example.createCriteria().andEqualTo("goodsId",goodsId);
        List<GoodsColorEntity> goodsColorEntities = goodsColorMapper.selectByExample(example);
        return goodsColorEntities;
    }

    @Override
    public int addGoodsColor(GoodsColorEntity goodsColorEntity) {
        goodsColorEntity.setCreatedTime(new Date());
        int rows = goodsColorMapper.insert(goodsColorEntity);
        return rows;
    }

    @Override
    public int deleteGoodsColor(int goodsColorId) {
        int rows = goodsColorMapper.deleteByPrimaryKey(goodsColorId);
        return rows;
    }

    @Override
    public int modifyGoodsColor(GoodsColorEntity goodsColorEntity) {
        goodsColorEntity.setCreatedTime(new Date());
        int rows = goodsColorMapper.updateByPrimaryKey(goodsColorEntity);
        return rows;
    }
}
